﻿@model FC.Data.ViewModels.Contests.ProblemCollection

@{
    Layout = "~/Views/Shared/_ManagerLayout.cshtml";
}

@using (Ajax.BeginForm(
    "SaveContest",
    "Manager",
    new AjaxOptions() {
        OnSuccess = "Success",
        OnFailure = "Failure"
    }
    ))
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        <h2>@ViewBag.Title</h2>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.Id)
        <div class="form-group">
            @Html.LabelFor(model => model.Code, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Code, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Code, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.State, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.State, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.State, "", new { @class = "text-danger" })
            </div>
        </div>
        <button id="Save" type="submit" class="btn btn-success">保存</button>
        <a class="btn btn-default" href="~/Manager/Contests">返回</a>
    </div>
}

@section Script{
    <script>
        function Success(result) {
            if (result.state == "ok") {
                alert("保存成功");
                window.location = "/Manager/Contests";
            }
            else {
                alert(result.message);
            }
        }
        function Failure() {
            alert("保存失败");
        }
    </script>
}